package com.exam.controller;


import com.exam.serviceimpl.BigModelNew;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.RequestBody;

import java.util.concurrent.ExecutionException;


@CrossOrigin(origins = "http://localhost:8088")


@RestController
@RequestMapping("/api")
public class BigModelController {
    private final BigModelNew bigModelService = new BigModelNew("", false);

    @PostMapping("/bigModel")
    public String handleBigModelRequest(@RequestBody String userText) throws ExecutionException, InterruptedException {
        // 将用户文本设置为大模型的问题
        BigModelNew.NewQuestion = userText;

        // 这里我们使用一个线程来模拟异步处理，实际应用中应该使用Spring的异步支持
        Thread thread = new Thread(() -> {
            try {
                BigModelNew.main(new String[]{});
            } catch (Exception e) {
                e.printStackTrace();
            }
        });
        thread.start();

        // 等待大模型处理完成，这里使用阻塞调用，实际应用中应该使用非阻塞方式
        thread.join();

        // 获取大模型的最终答案
        return BigModelNew.totalAnswer;
    }

}
